/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.simba.disambiguation;

import java.util.HashMap;
import org.simba.coherence.CoherenceMatrix;
import org.simba.utils.Configuration;
import org.simba.utils.EntityUriMap;
import org.simba.utils.NamedEntity;

/**
 * Final score = similarity + sum (apriori * coherence)/2^distance
 * @author ngonga
 */
public class LinearAlgorithm extends NormalizedHits {

    public static double alpha = 0.3;

    @Override
    public EntityUriMap getMapping(EntityUriMap similarities, CoherenceMatrix c,
            HashMap<String, Double> aprioriScores) {
        
        logger.info("Running linear algorithm");
        EntityUriMap sims = normalize(similarities);
        EntityUriMap normedAprioriMap = normalize(getAprioriMap(similarities, aprioriScores));
        EntityUriMap result = new EntityUriMap();

        HashMap<String, Double> map;
        for (NamedEntity e : sims.keySet()) {
            map = new HashMap<String, Double>();
            for (String uri : sims.getAllUris()) {
                map.put(uri, alpha * (sims.get(e, uri)) + (1 - alpha) * normedAprioriMap.get(e, uri));
            }
            result.put(e, map);
        }
        return result;
    }

    @Override
    public EntityUriMap getMapping(EntityUriMap similarities, CoherenceMatrix c,
            HashMap<String, Double> aprioriScores, Configuration config) {
        return getMapping(similarities, c, aprioriScores);
    }
}
